package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.InjectType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.order.domain.ProductionOperation;
import com.ruoyi.order.service.IProductionOperationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 生产操作管理Controller
 *
 * @author ruoyi
 * @date 2021-07-10
 */
@RestController
@RequestMapping("/system/operation")
public class ProductionOperationController extends BaseController
{
    @Autowired
    private IProductionOperationService productionOperationService;

    /**
     * 查询生产操作管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:operation:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductionOperation productionOperation)
    {
        startPage();
        List<ProductionOperation> list = productionOperationService.selectProductionOperationList(productionOperation);
        return getDataTable(list);
    }

    /**
     * 导出生产操作管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:operation:export')")
    @Log(title = "生产操作管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProductionOperation productionOperation)
    {
        List<ProductionOperation> list = productionOperationService.selectProductionOperationList(productionOperation);
        ExcelUtil<ProductionOperation> util = new ExcelUtil<ProductionOperation>(ProductionOperation.class);
        return util.exportExcel(list, "生产操作管理数据");
    }

    /**
     * 获取生产操作管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:operation:query')")
    @GetMapping(value = "/{operationId}")
    public AjaxResult getInfo(@PathVariable("operationId") Long operationId)
    {
        return AjaxResult.success(productionOperationService.selectProductionOperationById(operationId));
    }

    /**
     * 新增生产操作管理
     */
    @PreAuthorize("@ss.hasPermi('system:operation:add')")
    @Log(title = "生产操作管理", businessType = BusinessType.INSERT)
    @PostMapping
    @PropertyInject(type = InjectType.Insert)
    public AjaxResult add(@RequestBody ProductionOperation productionOperation)
    {
        return toAjax(productionOperationService.insertProductionOperation(productionOperation));
    }

    /**
     * 修改生产操作管理
     */
    @PreAuthorize("@ss.hasPermi('system:operation:edit')")
    @Log(title = "生产操作管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @PropertyInject(type = InjectType.Update)
    public AjaxResult edit(@RequestBody ProductionOperation productionOperation)
    {
        return toAjax(productionOperationService.updateProductionOperation(productionOperation));
    }

    /**
     * 删除生产操作管理
     */
    @PreAuthorize("@ss.hasPermi('system:operation:remove')")
    @Log(title = "生产操作管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{operationIds}")
    public AjaxResult remove(@PathVariable Long[] operationIds)
    {
        return toAjax(productionOperationService.deleteProductionOperationByIds(operationIds));
    }
}
